local HurtStrategy = require("gameLogic.fight.fightHurtStrategy.HurtStrategy")
local HurtPhysics = class("HurtPhysics", HurtStrategy)
local Hurt = require("gameLogic.fight.fightHurtStrategy.Hurt")
local FightConst = require("const.FightConst")
local AttributeConst = require("const.AttributeConst")
local AttrDataHelper = require("data.helper.AttrDataHelper")

function HurtPhysics:ctor(config, skill)
    HurtPhysics.super.ctor(self, config, skill)
end

function HurtPhysics:hurt(target)
    local ratio = self._config.ratio
    local entity = self._skill:getEntity()
    local value = (entity:getAttrValue(AttributeConst.ATTACK) * ratio)
    local pierce = entity:getAttrValue(AttributeConst.PHYSICS_PIERCE)
    local defense = target:getAttrValue(AttributeConst.DEFENSE)
    local pieDefense = defense - (pierce / (pierce + FightConst.PIERCE_FIX_RATIO) * defense)
    local hurt = value - (pieDefense / (pieDefense + FightConst.DEFENSE_FIX_RATIO) * value)

    hurt = hurt <= 0 and 1 or hurt
    local finalHurt, isCrit = self:_critHurt(hurt)
    local hurtAdd = entity:getAttrValue(AttributeConst.HURT_ADD)

    local feature = entity:getFeature()
    local raceAdd = entity:getAttrValue(AttrDataHelper.getRaceHurtAddAttrId(feature.race))
    local sexAdd = entity:getAttrValue(AttrDataHelper.getSexHurtAttrId(feature.sex))

    finalHurt = finalHurt + (finalHurt * (hurtAdd + raceAdd + sexAdd / 1000))
    local physics_resist = target:getAttrValue(AttributeConst.PHYSICS_RESIST)
    local percent = physics_resist / 1000 > 0.8 and 0.8 or physics_resist / 1000
    finalHurt = finalHurt - (finalHurt * percent) -- 抗性千分比

    local allResist = target:getAttrValue(AttributeConst.HURT_RESIST)
    finalHurt = finalHurt - (finalHurt * (allResist / 1000))
    finalHurt = math.floor(finalHurt)
    local hurtObj = Hurt.new(finalHurt, isCrit, AttributeConst.ELEMENT_PHYSICS, self._skill:canCounterattack(), entity)
    return hurtObj
end

return HurtPhysics
